package com.tarena.lbs.passport.repository;

import com.tarena.lbs.common.passport.converter.LoginConverter;
import com.tarena.lbs.passport.mapper.AdminMapper;
import com.tarena.lbs.passport.mapper.UserMapper;
import com.tarena.lbs.pojo.passport.bo.AdminBO;
import com.tarena.lbs.pojo.passport.bo.UserBO;
import com.tarena.lbs.pojo.passport.dos.AdminDO;
import com.tarena.lbs.pojo.passport.dos.UserDO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

@Repository
public class LoginRepository {
    @Autowired(required = false)
    private UserMapper userMapper;
    @Autowired(required = false)
    private AdminMapper adminMapper;
    @Autowired
    private LoginConverter loginConverter;
    public UserBO getUserByUsername(String username) {
        UserDO userDO= userMapper.selectUserByPhone(username);
        UserBO userBO=loginConverter.userdo2userbo(userDO);
        return userBO;
    }

    public AdminBO getUserByPhone(String phone) {
        List<AdminDO> adminDOS=adminMapper.selectAdminByPhone(phone);
        if (!CollectionUtils.isEmpty(adminDOS)){
            return loginConverter.admindo2adminbo(adminDOS.get(0));
        }
        return null;
    }
}
